import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class RunThreadpool {
    public static void main(String[] args) {
        BlockingQueue<Runnable> bq = new LinkedBlockingQueue<Runnable>(5);
        ThreadPoolExecutor pool = new ThreadPoolExecutor(3,6,2000,TimeUnit.MILLISECONDS,bq);
        for(int i =0;i<8;i++){
            pool.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread().getId() + "is running...");
                    try{
                        Thread.sleep(800);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });

        }
        System.out.println("池中线程数："+ pool.getPoolSize());
        pool.shutdown();
//        List<Runnable> undo =  pool.shutdownNow();
//        System.out.println("未执行的任务"+undo.size());
//        try{
//            Thread.sleep(5000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//        System.out.println("池中线程数："+ pool.getPoolSize());

    }
}
